{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import warnings\n",
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>address</th>\n",
       "      <th>admissions</th>\n",
       "      <th>answerurl</th>\n",
       "      <th>belong</th>\n",
       "      <th>central</th>\n",
       "      <th>city_id</th>\n",
       "      <th>city_name</th>\n",
       "      <th>code_enroll</th>\n",
       "      <th>colleges_level</th>\n",
       "      <th>county_id</th>\n",
       "      <th>...</th>\n",
       "      <th>type_name</th>\n",
       "      <th>view_month</th>\n",
       "      <th>view_month_number</th>\n",
       "      <th>view_total</th>\n",
       "      <th>view_total_number</th>\n",
       "      <th>view_week</th>\n",
       "      <th>view_week_number</th>\n",
       "      <th>view_year</th>\n",
       "      <th>bd经度</th>\n",
       "      <th>bd纬度</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>广东省深圳市南山区学苑大道1088 号</td>\n",
       "      <td>2</td>\n",
       "      <td>https://m-view.eol.cn/h5/zsgk/answer_noresult....</td>\n",
       "      <td>广东省</td>\n",
       "      <td>2</td>\n",
       "      <td>4403</td>\n",
       "      <td>深圳市</td>\n",
       "      <td>1432500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>理工类</td>\n",
       "      <td>18.9w</td>\n",
       "      <td>188928</td>\n",
       "      <td>296.7w</td>\n",
       "      <td>2967043</td>\n",
       "      <td>3.8w</td>\n",
       "      <td>38361</td>\n",
       "      <td>365397</td>\n",
       "      <td>114.005913</td>\n",
       "      <td>22.603944</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>福建省厦门市思明区思明南路422号</td>\n",
       "      <td>1</td>\n",
       "      <td>https://m-view.eol.cn/h5/zsgk/answer_noresult....</td>\n",
       "      <td>教育部</td>\n",
       "      <td>2</td>\n",
       "      <td>3502</td>\n",
       "      <td>厦门市</td>\n",
       "      <td>1038400</td>\n",
       "      <td>NaN</td>\n",
       "      <td>350203</td>\n",
       "      <td>...</td>\n",
       "      <td>综合类</td>\n",
       "      <td>93.6w</td>\n",
       "      <td>936051</td>\n",
       "      <td>3846.4w</td>\n",
       "      <td>38463977</td>\n",
       "      <td>16.5w</td>\n",
       "      <td>164583</td>\n",
       "      <td>1937298</td>\n",
       "      <td>118.108573</td>\n",
       "      <td>24.442324</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>望江校区：四川省成都市一环路南一段24号,华西校区：四川省成都市人民南路三段17号,江安校区...</td>\n",
       "      <td>1</td>\n",
       "      <td>https://answer.eol.cn/fillmess/index?id=677&amp;so...</td>\n",
       "      <td>教育部</td>\n",
       "      <td>2</td>\n",
       "      <td>5101</td>\n",
       "      <td>成都市</td>\n",
       "      <td>1061000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>510107</td>\n",
       "      <td>...</td>\n",
       "      <td>综合类</td>\n",
       "      <td>89.3w</td>\n",
       "      <td>893379</td>\n",
       "      <td>3063.9w</td>\n",
       "      <td>30638627</td>\n",
       "      <td>14.4w</td>\n",
       "      <td>143844</td>\n",
       "      <td>1943694</td>\n",
       "      <td>104.090633</td>\n",
       "      <td>30.637031</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>湖北省武汉市武昌区八一路299号</td>\n",
       "      <td>1</td>\n",
       "      <td>https://answer.eol.cn/fillmess/index?id=621&amp;so...</td>\n",
       "      <td>教育部</td>\n",
       "      <td>2</td>\n",
       "      <td>4201</td>\n",
       "      <td>武汉市</td>\n",
       "      <td>1048600</td>\n",
       "      <td>NaN</td>\n",
       "      <td>420106</td>\n",
       "      <td>...</td>\n",
       "      <td>综合类</td>\n",
       "      <td>19.7w</td>\n",
       "      <td>196900</td>\n",
       "      <td>2505.5w</td>\n",
       "      <td>25054820</td>\n",
       "      <td>3.6w</td>\n",
       "      <td>36436</td>\n",
       "      <td>426949</td>\n",
       "      <td>114.372930</td>\n",
       "      <td>30.543803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>广州校区南校园：广东省广州市海珠区新港西路135号,广州校区北校园：广东省广州市越秀区中山二...</td>\n",
       "      <td>1</td>\n",
       "      <td>https://answer.eol.cn/fillmess/index?id=682&amp;so...</td>\n",
       "      <td>教育部</td>\n",
       "      <td>2</td>\n",
       "      <td>4401</td>\n",
       "      <td>广州市</td>\n",
       "      <td>1055800</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>综合类</td>\n",
       "      <td>61.5w</td>\n",
       "      <td>614841</td>\n",
       "      <td>2327w</td>\n",
       "      <td>23269905</td>\n",
       "      <td>11w</td>\n",
       "      <td>109971</td>\n",
       "      <td>1271007</td>\n",
       "      <td>113.304864</td>\n",
       "      <td>23.102915</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 45 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                             address  admissions  \\\n",
       "0                                广东省深圳市南山区学苑大道1088 号           2   \n",
       "1                                  福建省厦门市思明区思明南路422号           1   \n",
       "2  望江校区：四川省成都市一环路南一段24号,华西校区：四川省成都市人民南路三段17号,江安校区...           1   \n",
       "3                                   湖北省武汉市武昌区八一路299号           1   \n",
       "4  广州校区南校园：广东省广州市海珠区新港西路135号,广州校区北校园：广东省广州市越秀区中山二...           1   \n",
       "\n",
       "                                           answerurl belong  central  city_id  \\\n",
       "0  https://m-view.eol.cn/h5/zsgk/answer_noresult....    广东省        2     4403   \n",
       "1  https://m-view.eol.cn/h5/zsgk/answer_noresult....    教育部        2     3502   \n",
       "2  https://answer.eol.cn/fillmess/index?id=677&so...    教育部        2     5101   \n",
       "3  https://answer.eol.cn/fillmess/index?id=621&so...    教育部        2     4201   \n",
       "4  https://answer.eol.cn/fillmess/index?id=682&so...    教育部        2     4401   \n",
       "\n",
       "  city_name  code_enroll  colleges_level  county_id  ... type_name  \\\n",
       "0       深圳市      1432500             NaN          0  ...       理工类   \n",
       "1       厦门市      1038400             NaN     350203  ...       综合类   \n",
       "2       成都市      1061000             NaN     510107  ...       综合类   \n",
       "3       武汉市      1048600             NaN     420106  ...       综合类   \n",
       "4       广州市      1055800             NaN          0  ...       综合类   \n",
       "\n",
       "   view_month  view_month_number  view_total view_total_number  view_week  \\\n",
       "0       18.9w             188928      296.7w           2967043       3.8w   \n",
       "1       93.6w             936051     3846.4w          38463977      16.5w   \n",
       "2       89.3w             893379     3063.9w          30638627      14.4w   \n",
       "3       19.7w             196900     2505.5w          25054820       3.6w   \n",
       "4       61.5w             614841       2327w          23269905        11w   \n",
       "\n",
       "   view_week_number view_year        bd经度       bd纬度  \n",
       "0             38361    365397  114.005913  22.603944  \n",
       "1            164583   1937298  118.108573  24.442324  \n",
       "2            143844   1943694  104.090633  30.637031  \n",
       "3             36436    426949  114.372930  30.543803  \n",
       "4            109971   1271007  113.304864  23.102915  \n",
       "\n",
       "[5 rows x 45 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "df_高校=pd.read_excel(\"全国高校.xlsx\")\n",
    "df_高校.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyecharts\n",
    "from pyecharts.charts import *\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.commons.utils import JsCode\n",
    "import pyecharts.charts as pyec\n",
    "import pyecharts.options as opts\n",
    "from pyecharts.globals import ThemeType\n",
    "import random\n",
    "import numpy as np\n",
    "import json\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import WordCloud\n",
    "from pyecharts.charts import Funnel\n",
    "from pyecharts.faker import Faker"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>view_month_number</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>厦门大学</td>\n",
       "      <td>936051</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>四川大学</td>\n",
       "      <td>893379</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>西南大学</td>\n",
       "      <td>662112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>中山大学</td>\n",
       "      <td>614841</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>电子科技大学</td>\n",
       "      <td>552633</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>中南大学</td>\n",
       "      <td>487929</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>127</th>\n",
       "      <td>华北理工大学</td>\n",
       "      <td>476568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>66</th>\n",
       "      <td>中国民航大学</td>\n",
       "      <td>474846</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>华中科技大学</td>\n",
       "      <td>473400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>成都理工大学</td>\n",
       "      <td>467385</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>郑州大学</td>\n",
       "      <td>464304</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>海南大学</td>\n",
       "      <td>461046</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>暨南大学</td>\n",
       "      <td>457857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>深圳大学</td>\n",
       "      <td>455475</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>南昌大学</td>\n",
       "      <td>451791</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       name  view_month_number\n",
       "1      厦门大学             936051\n",
       "2      四川大学             893379\n",
       "8      西南大学             662112\n",
       "4      中山大学             614841\n",
       "10   电子科技大学             552633\n",
       "7      中南大学             487929\n",
       "127  华北理工大学             476568\n",
       "66   中国民航大学             474846\n",
       "16   华中科技大学             473400\n",
       "37   成都理工大学             467385\n",
       "20     郑州大学             464304\n",
       "29     海南大学             461046\n",
       "38     暨南大学             457857\n",
       "34     深圳大学             455475\n",
       "35     南昌大学             451791"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "view_month_number=df_高校[[\"name\",\"view_month_number\"]].sort_values(by = \"view_month_number\",ascending = False).head(15) #获取月浏览量前十高校\n",
    "view_month_number"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 浏览top高校"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\18018\\\\Desktop\\\\交互式数据可视化\\\\final\\\\html\\\\月浏览top12.html'"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "view_month_number=df_高校[[\"name\",\"view_month_number\"]].sort_values(by = \"view_month_number\",ascending = False).head(12)\n",
    "\n",
    "bar1 = (Bar()\n",
    "            .add_xaxis(view_month_number[\"name\"].tolist())\n",
    "            .add_yaxis(\"\",view_month_number[\"view_month_number\"].tolist())\n",
    "            .set_series_opts(label_opts=opts.LabelOpts(is_show=True, \n",
    "                                                       position='outsideLeft',\n",
    "                                                       font_style='italic'),\n",
    "                            itemstyle_opts=opts.ItemStyleOpts(\n",
    "                                color=JsCode(\"\"\"new echarts.graphic.LinearGradient(1, 0, 0, 0, \n",
    "                                             [{\n",
    "                                                 offset: 0,\n",
    "                                                 color: 'rgb(116, 235, 213)'\n",
    "                                             }, {\n",
    "                                                 offset: 1,\n",
    "                                                 color: 'rgb(172, 182, 229)'\n",
    "                                             }])\"\"\"))\n",
    "                            )\n",
    "            .set_global_opts(\n",
    "                title_opts=opts.TitleOpts(title=\"月浏览量top12的学校\",\n",
    "                                          subtitle='',\n",
    "                                          title_textstyle_opts=opts.TextStyleOpts(), pos_left=\"center\", pos_top=\"0\",),\n",
    "\n",
    "            )\n",
    "            .reversal_axis()\n",
    "     \n",
    "        )\n",
    "# bar1.render_notebook()\n",
    "bar1.render(\"html/月浏览top12.html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\18018\\\\Desktop\\\\交互式数据可视化\\\\final\\\\html\\\\总浏览top12.html'"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "view_total_number=df_高校[[\"name\",\"view_total_number\"]].sort_values(by = \"view_total_number\",ascending = False).head(12)\n",
    "\n",
    "bar2 = (Bar(init_opts=opts.InitOpts(width=\"1000px\"))\n",
    "            .add_xaxis(view_total_number[\"name\"].tolist())\n",
    "            .add_yaxis(\"\",view_total_number[\"view_total_number\"].tolist())\n",
    "            .set_series_opts(label_opts=opts.LabelOpts(is_show=True, \n",
    "                                                       position='outsideLeft',\n",
    "                                                       font_style='italic'),\n",
    "                            itemstyle_opts=opts.ItemStyleOpts(\n",
    "                                color=JsCode(\"\"\"new echarts.graphic.LinearGradient(1, 0, 0, 0, \n",
    "                                             [{\n",
    "                                                 offset: 0,\n",
    "                                                 color: 'rgb(116, 235, 213)'\n",
    "                                             }, {\n",
    "                                                 offset: 1,\n",
    "                                                 color: 'rgb(172, 182, 229)'\n",
    "                                             }])\"\"\"))\n",
    "                            )\n",
    "            .set_global_opts(\n",
    "                title_opts=opts.TitleOpts(title=\"总浏览量top12的学校\",\n",
    "                                          subtitle='厦门大学稳居第一',\n",
    "                                          title_textstyle_opts=opts.TextStyleOpts(), pos_left=\"center\", pos_top=\"0\",),\n",
    "                legend_opts=opts.LegendOpts(orient=\"vertical\", pos_top=\"35%\", pos_right=\"0%\"),\n",
    "\n",
    "            )\n",
    "            .reversal_axis()\n",
    "        )\n",
    "\n",
    "bar2.render(\"html/总浏览top12.html\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 高校分布热力图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pyecharts.charts.basic_charts.geo.Geo at 0x1b68b50cfa0>"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "geo = Geo(\n",
    "    init_opts=opts.InitOpts(\n",
    "        theme='walden',\n",
    "        width='1000px',\n",
    "        height='800px'\n",
    "    )\n",
    ")\n",
    "\n",
    "geo.add_schema(\n",
    "    maptype=\"china\",\n",
    "    zoom=1,\n",
    "    is_roam=False,\n",
    "    emphasis_label_opts=opts.LabelOpts(is_show=False),\n",
    "    #itemstyle_opts=opts.ItemStyleOpts(border_color=\"#1E90FF\", border_width=1.2),\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\18018\\\\Desktop\\\\交互式数据可视化\\\\final\\\\html\\\\地图热力图.html'"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = []\n",
    "for idx, row in df_高校.iterrows():\n",
    "    geo.add_coordinate(row['name'], row['bd经度'], row['bd纬度'])\n",
    "    data.append([row['name'], 1])\n",
    "\n",
    "geo.add(\n",
    "    '',\n",
    "    data,\n",
    "    type_='heatmap',\n",
    "    is_selected=True,\n",
    "    symbol_size=1,\n",
    "    is_large=True,\n",
    "    blur_size=10,\n",
    "    point_size=3,\n",
    "    itemstyle_opts={\n",
    "        'color': '#00BFFF',\n",
    "        'opacity':0.5,\n",
    "        'shadowBlur': 1,\n",
    "        'shadowColor': 'rgba(0,0,0,0.5)'\n",
    "    },\n",
    "    label_opts=opts.LabelOpts(is_show=False),\n",
    "    tooltip_opts=opts.TooltipOpts(is_show=False),\n",
    ")\n",
    "geo.set_global_opts(\n",
    "    title_opts=opts.TitleOpts(\n",
    "        title=\"中国高校分布热力图\", pos_top='3%', pos_left='center', \n",
    "        #title_textstyle_opts=opts.TextStyleOpts(color='#00BFFF', font_size=20)\n",
    "        ),\n",
    "    legend_opts=opts.LegendOpts(is_show=True, pos_left='center', pos_top='4%'),\n",
    "    visualmap_opts=opts.VisualMapOpts(\n",
    "        is_show=False,\n",
    "        max_=2,\n",
    "        series_index=0,\n",
    "        range_color=['blue', 'blue', 'green', 'yellow', 'red']\n",
    "        ),\n",
    ")\n",
    "\n",
    "prov_count = list(dict(df_高校['province_name'].value_counts()).items())\n",
    "prov_count=[(x, int(y)) for x, y in prov_count]\n",
    "map_chart = Map()\n",
    "map_chart.add('',\n",
    "              data_pair=prov_count,\n",
    "              maptype='china',\n",
    "              is_map_symbol_show=False,\n",
    "              is_roam=False,\n",
    "              label_opts=opts.LabelOpts(is_show=False),\n",
    "              tooltip_opts=opts.TooltipOpts(is_show=True, formatter='{b}: {c}所'),\n",
    "              itemstyle_opts={'opacity':0}\n",
    "              )\n",
    "\n",
    "grid = Grid(init_opts=opts.InitOpts(theme='walden', width='980px', height='800px'))\n",
    "\n",
    "grid.add(geo, is_control_axis_index=False, grid_opts=opts.GridOpts())\n",
    "grid.add(map_chart, is_control_axis_index=False, grid_opts=opts.GridOpts())\n",
    "\n",
    "grid.render(\"html/地图热力图.html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 本专科分布饼图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "level = df_高校.groupby('level_name')['name'].count().reset_index()\n",
    "level.columns = ['类别','计数']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('普通本科', 1296), ('专科（高职）', 784)]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "level_data = [(row['类别'], row['计数']) for _, row in level.iterrows()]\n",
    "level_data = sorted(level_data, key=lambda x: x[1], reverse=True)\n",
    "level_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "pie1 = (Pie(init_opts=opts.InitOpts(theme=ThemeType.LIGHT, width='900px'))\n",
    "       .add('', level_data,\n",
    "            radius=[\"30%\", \"45%\"],\n",
    "             center=[\"50%\", \"50%\"],#圆心位置，第一个坐标点为横轴位置，第二个坐标点为纵轴位置\n",
    "            rosetype=\"radius\")\n",
    "       .set_global_opts(title_opts=opts.TitleOpts(title=\"高校本专科分布\",\n",
    "                                                  pos_left = \"20%\",pos_top = \"15%\"),\n",
    "                        legend_opts=opts.LegendOpts(is_show=False),)\n",
    "       .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}: {d}%\"))\n",
    "        .render(\"html/本专科分布.html\")\n",
    "      )\n",
    "# pie1.render(\"html/本专科分布.html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 公办or民办"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\18018\\\\Desktop\\\\交互式数据可视化\\\\final\\\\html\\\\性质分布.html'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nature =df_高校.groupby('nature_name')['name'].count().reset_index()\n",
    "nature.columns = ['性质','计数']\n",
    "nature_data = [(row['性质'], row['计数']) for _, row in nature.iterrows()]\n",
    "nature_data = sorted(nature_data, key=lambda x: x[1], reverse=True)\n",
    "\n",
    "pie2 = (Pie(init_opts=opts.InitOpts(theme=ThemeType.MACARONS, width='900px'))\n",
    "       .add('', nature_data,\n",
    "            radius=[\"30%\", \"45%\"],\n",
    "            center=[\"50%\", \"50%\"], \n",
    "            rosetype=\"radius\")\n",
    "       .set_global_opts(title_opts=opts.TitleOpts(title=\"高校性质分布\",\n",
    "                                                  pos_left = \"50%\",pos_top = \"15%\"),\n",
    "                        legend_opts=opts.LegendOpts(is_show=False),)\n",
    "         .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}: {d}%\"))\n",
    "      )\n",
    "pie2.render(\"html/性质分布.html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'str' object has no attribute 'options'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-13-063de9b1b280>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m grid = (Grid(init_opts=opts.InitOpts(theme=ThemeType.MACARONS, width=1000))\n\u001b[0m\u001b[0;32m      2\u001b[0m         \u001b[1;33m.\u001b[0m\u001b[0madd\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpie1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mgrid_opts\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mopts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mGridOpts\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m         \u001b[1;33m.\u001b[0m\u001b[0madd\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpie2\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mgrid_opts\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mopts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mGridOpts\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m         )\n\u001b[0;32m      5\u001b[0m \u001b[0mgrid\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrender_notebook\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\18018\\.idea\\anaconda\\lib\\site-packages\\pyecharts\\charts\\composite_charts\\grid.py\u001b[0m in \u001b[0;36madd\u001b[1;34m(self, chart, grid_opts, grid_index, is_control_axis_index)\u001b[0m\n\u001b[0;32m     30\u001b[0m     ):\n\u001b[0;32m     31\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0moptions\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 32\u001b[1;33m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0moptions\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcopy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdeepcopy\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mchart\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0moptions\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     33\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mchart_id\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mchart\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mchart_id\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     34\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0moptions\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgrid\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtitle\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'str' object has no attribute 'options'"
     ]
    }
   ],
   "source": [
    "grid = (Grid(init_opts=opts.InitOpts(theme=ThemeType.MACARONS, width=1000))\n",
    "        .add(pie1, grid_opts=opts.GridOpts())\n",
    "        .add(pie2, grid_opts=opts.GridOpts())\n",
    "        )\n",
    "grid.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 高校类别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min', 'westeros':'https://assets.pyecharts.org/assets/themes/westeros'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"478d87c0f7774ab19f467a0c487eaed1\" style=\"width:200; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts', 'westeros'], function(echarts) {\n",
       "                var chart_478d87c0f7774ab19f467a0c487eaed1 = echarts.init(\n",
       "                    document.getElementById('478d87c0f7774ab19f467a0c487eaed1'), 'westeros', {renderer: 'canvas'});\n",
       "                var option_478d87c0f7774ab19f467a0c487eaed1 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"clockwise\": true,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u7efc\\u5408\\u7c7b\",\n",
       "                    \"value\": 667\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u7406\\u5de5\\u7c7b\",\n",
       "                    \"value\": 600\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u533b\\u836f\\u7c7b\",\n",
       "                    \"value\": 180\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8d22\\u7ecf\\u7c7b\",\n",
       "                    \"value\": 179\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5e08\\u8303\\u7c7b\",\n",
       "                    \"value\": 162\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u519c\\u6797\\u7c7b\",\n",
       "                    \"value\": 67\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u827a\\u672f\\u7c7b\",\n",
       "                    \"value\": 67\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u653f\\u6cd5\\u7c7b\",\n",
       "                    \"value\": 60\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8bed\\u8a00\\u7c7b\",\n",
       "                    \"value\": 30\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u519b\\u4e8b\\u7c7b\",\n",
       "                    \"value\": 27\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4f53\\u80b2\\u7c7b\",\n",
       "                    \"value\": 17\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c11\\u65cf\\u7c7b\",\n",
       "                    \"value\": 14\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5176\\u4ed6\",\n",
       "                    \"value\": 10\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                \"30%\",\n",
       "                \"45%\"\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"50%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"roseType\": \"radius\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{b}: {d}%\"\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u7efc\\u5408\\u7c7b\",\n",
       "                \"\\u7406\\u5de5\\u7c7b\",\n",
       "                \"\\u533b\\u836f\\u7c7b\",\n",
       "                \"\\u8d22\\u7ecf\\u7c7b\",\n",
       "                \"\\u5e08\\u8303\\u7c7b\",\n",
       "                \"\\u519c\\u6797\\u7c7b\",\n",
       "                \"\\u827a\\u672f\\u7c7b\",\n",
       "                \"\\u653f\\u6cd5\\u7c7b\",\n",
       "                \"\\u8bed\\u8a00\\u7c7b\",\n",
       "                \"\\u519b\\u4e8b\\u7c7b\",\n",
       "                \"\\u4f53\\u80b2\\u7c7b\",\n",
       "                \"\\u6c11\\u65cf\\u7c7b\",\n",
       "                \"\\u5176\\u4ed6\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": false,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u5168\\u56fd\\u9ad8\\u6821\\u7c7b\\u522b\\u5206\\u5e03\",\n",
       "            \"left\": \"50%\",\n",
       "            \"top\": \"10%\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_478d87c0f7774ab19f467a0c487eaed1.setOption(option_478d87c0f7774ab19f467a0c487eaed1);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x1b68b502bb0>"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type1= df_高校.groupby(\"type_name\")[\"name\"].count().reset_index()\n",
    "type1.columns = [\"类别\",\"计数\"]\n",
    "type_data = [(row[\"类别\"],row[\"计数\"]) for i,row in type1.iterrows()]\n",
    "type_data = sorted(type_data,key = lambda x:x[1],reverse = True)\n",
    "\n",
    "pie3 = (Pie(init_opts=opts.InitOpts(theme=ThemeType.WESTEROS, width=200))\n",
    "       .add('', type_data,\n",
    "            radius=[\"30%\", \"45%\"],\n",
    "            center=[\"50%\", \"50%\"],\n",
    "            rosetype=\"radius\")\n",
    "       .set_global_opts(title_opts=opts.TitleOpts(title=\"全国高校类别分布\",\n",
    "                                                  pos_left = \"50%\",pos_top = \"10%\"),\n",
    "                        legend_opts=opts.LegendOpts(is_show=False),)\n",
    "       .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}: {d}%\"))\n",
    "      )\n",
    "pie3.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "school_type = list(dict(df_高校['type_name'].value_counts()).items())\n",
    "topschool_type = list(dict(df_高校['type_name'][df_高校['dual_class_name']=='双一流'].value_counts()).items())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "school_type=[(x, int(y)) for x, y in school_type]\n",
    "topschool_type=[(x, int(y)) for x, y in topschool_type]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\18018\\\\Desktop\\\\交互式数据可视化\\\\final\\\\html\\\\高校类型.html'"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pie = Pie(\n",
    "    init_opts=opts.InitOpts(\n",
    "        theme='light',\n",
    "        width='1000px',\n",
    "        height='600px',\n",
    "        # bg_color='rgb(0,0,0)'\n",
    "        )\n",
    ")\n",
    "pie.add(\n",
    "    \"\",\n",
    "    school_type,\n",
    "    # 指定饼图中心位置\n",
    "    center=[\"25%\", \"50%\"],\n",
    "    # 将饼图尺寸相应缩小，不然饼图会重叠\n",
    "    radius=[\"25%\", \"35%\"],\n",
    "    label_opts=opts.LabelOpts(formatter='{b}\\n{d}%')\n",
    ")\n",
    "\n",
    "pie.add(\n",
    "    \"\",\n",
    "    topschool_type,\n",
    "    # 指定饼图中心位置\n",
    "    center=[\"70%\", \"50%\"],\n",
    "    # 将饼图尺寸相应缩小，不然饼图会重叠\n",
    "    radius=[\"25%\", \"35%\"],\n",
    "    label_opts=opts.LabelOpts(formatter='{b}\\n{d}%')\n",
    ")\n",
    "\n",
    "pie.set_global_opts(\n",
    "    legend_opts=opts.LegendOpts(is_show=False),\n",
    "    title_opts=[\n",
    "        dict(text='全国高校', left='20.5%', top='48%', textStyle=dict(color='#00BFFF', fontSize=20)),\n",
    "        dict(text='双一流\\n高校 ',left='70%',top='47%', textAlign='center',textStyle=dict(color='#00BFFF', fontSize=20))\n",
    "    ]\n",
    ")\n",
    "pie.render(\"html/高校类型.html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\18018\\\\Desktop\\\\交互式数据可视化\\\\final\\\\html\\\\高校类型词云图.html'"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "words = school_type\n",
    "w = (\n",
    "    WordCloud()\n",
    "    .add(\"\", words, word_size_range=[32, 55])\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"高校类型\",pos_left = \"20%\",pos_top = \"10%\"))    \n",
    ")\n",
    "w.render(\"html/高校类型词云图.html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [],
   "source": [
    "all_sch = df_高校.groupby('province_name')['name'].count().reset_index()\n",
    "\n",
    "all_num=[]\n",
    "for idx, row in all_sch.iterrows():\n",
    "    all_num.append(dict(name=row['province_name'], value=row['name']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\18018\\\\Desktop\\\\交互式数据可视化\\\\final\\\\html\\\\省市数量排行树图.html'"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tree = (\n",
    "      TreeMap(init_opts=opts.InitOpts(\n",
    "        theme=ThemeType.WESTEROS,\n",
    "        width='1000px',\n",
    "        height='600px',\n",
    "        ))\n",
    "      .add(\"数量排名\",\n",
    "           all_num,\n",
    "           leaf_depth=1,\n",
    "           label_opts=opts.LabelOpts(position=\"inside\", formatter='{b}: {c}所'),\n",
    "          levels=[\n",
    "            opts.TreeMapLevelsOpts(\n",
    "                treemap_itemstyle_opts=opts.TreeMapItemStyleOpts(\n",
    "                    border_color=\"#555\", border_width=2, gap_width=2\n",
    "                )\n",
    "            ),\n",
    "            opts.TreeMapLevelsOpts(\n",
    "                color_saturation=[0.3, 0.6],\n",
    "                treemap_itemstyle_opts=opts.TreeMapItemStyleOpts(\n",
    "                    border_color_saturation=0.7, gap_width=2, border_width=1\n",
    "                ),\n",
    "            ),\n",
    "            opts.TreeMapLevelsOpts(\n",
    "                color_saturation=[0.3, 0.5],\n",
    "                treemap_itemstyle_opts=opts.TreeMapItemStyleOpts(\n",
    "                    border_color_saturation=0.2, gap_width=1\n",
    "                ),\n",
    "            ),\n",
    "            opts.TreeMapLevelsOpts(color_saturation=[0.3, 0.5]),\n",
    "        ],)\n",
    "#       .set_series_opts(label_opts=opts.LabelOpts(position='inside'))\n",
    "       .set_global_opts(title_opts=opts.TitleOpts(title = '各省市高校数量',subtitle = ''))\n",
    "      )\n",
    "\n",
    "\n",
    "tree.render(\"html/省市数量排行树图.html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "city_count = list(dict(df_高校['city_name'].value_counts()).items())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('北京市', 35),\n",
       " ('上海市', 17),\n",
       " ('南京市', 13),\n",
       " ('成都市', 9),\n",
       " ('广州市', 7),\n",
       " ('武汉市', 7),\n",
       " ('西安市', 7),\n",
       " ('天津市', 6),\n",
       " ('哈尔滨市', 4),\n",
       " ('长沙市', 4)]"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city_count_top = list(dict(df_高校['city_name'][df_高校['dual_class_name']=='双一流'].value_counts()).items())\n",
    "city_count_top10 = city_count_top[:10]\n",
    "city_count_top10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\18018\\\\Desktop\\\\交互式数据可视化\\\\final\\\\html\\\\双一流城市top10.html'"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "city_count = list(dict(df_高校['city_name'].value_counts()).items())\n",
    "city_count_top = list(dict(df_高校['city_name'][df_高校['dual_class_name']=='双一流'].value_counts()).items())\n",
    "city_count_top10 = city_count_top[:10]\n",
    "\n",
    "\n",
    "x_data=['北京市','上海市','南京市','成都市','西安市','武汉市','广州市','天津市','哈尔滨市','长沙市']\n",
    "y_data=[35,17,13,9,7,7,7,6,4,4]\n",
    "data1=[[x_data[i], y_data[i]] for i in range(len(x_data))]\n",
    "(\n",
    "    Funnel(init_opts=opts.InitOpts(theme=ThemeType. INFOGRAPHIC,width=\"900px\", height=\"600px\"))\n",
    "    .add(\n",
    "        series_name=\"\",\n",
    "        data_pair=data1,\n",
    "        gap=2,\n",
    "        tooltip_opts=opts.TooltipOpts(trigger=\"item\", formatter=\"{a} <br/>{b} : {c}%\"),\n",
    "        label_opts=opts.LabelOpts(is_show=True, position=\"inside\"),\n",
    "        itemstyle_opts=opts.ItemStyleOpts(border_color=\"#fff\", border_width=1),\n",
    "    )\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"城市双一流院校top10\", pos_left = \"\",pos_top = \"2%\"),\n",
    "                    legend_opts=opts.LegendOpts(\n",
    "                type_=\"scroll\", pos_left=\"90%\", orient=\"vertical\",pos_top=\"15%\"\n",
    "            ),)\n",
    "     .render(\"html/双一流城市top10.html\")\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "各省份高校数量 = [i for i in df_高校['province_name'].value_counts().items()] # value_counts()用于提取重复字段并按数量从多到少排序，再转成列表包含元组的形式\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'C:\\\\Users\\\\18018\\\\Desktop\\\\交互式数据可视化\\\\final\\\\html\\\\高校分布地图.html'"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "map_1 = (\n",
    "        Map() # 导入pyecharts.charts中的Map\n",
    "        .add(\"各省份高校数量\", [list(i) for i in 各省份高校数量], \"china\") # 可以指定各国家，省份\n",
    "        # 上语句中传入数据必须是列表内包含列表，所以需要将以上列表包含元组进行转换\n",
    "        .set_global_opts(\n",
    "            title_opts=opts.TitleOpts(title=\"全国高校各省份分布图\"),\n",
    "            legend_opts=opts.LegendOpts(is_show=False), # 是否显示图例\n",
    "            visualmap_opts=opts.VisualMapOpts(max_=140, is_piecewise=True), # is_piecewise=True表示使用分段显示（而不是手动拖拽范围）\n",
    "        )\n",
    "    )\n",
    "\n",
    "# map_1.render() # 将地图以html形式保存在工作目录下\n",
    "map_1.render(\"html/高校分布地图.html\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "\n",
    "data_gd = [list(i) for i in 各省份高校数量]\n",
    "\n",
    "map_1 = (\n",
    "Map(init_opts=opts.InitOpts(width=\"1200px\", height=\"900px\", page_title='全国高校各省份分布图'))\n",
    "        .add(\n",
    "        '各省份高校数量',\n",
    "        data_gd,\n",
    "        maptype='china',\n",
    "        is_roam=True,\n",
    "        is_selected=True,\n",
    "        is_map_symbol_show=True  # 是否标记图形\n",
    "    )\n",
    "\n",
    "        .set_global_opts(\n",
    "        title_opts=opts.TitleOpts(title=\"全国高校各省份分布图\",\n",
    "                                  \n",
    "                                  title_target=\"blank\",  # 新窗口打开\n",
    "                                  subtitle=\"\",  # 副标题\n",
    "                                  \n",
    "                                  subtitle_target=\"self\"),  # 当前窗口打开\n",
    "\n",
    "        visualmap_opts=opts.VisualMapOpts(is_show=True,  # 视觉映射配置\n",
    "                                          max_=135,\n",
    "                                          min_=1,\n",
    "                                          is_calculable=True,  # 是否显示拖拽用的手柄\n",
    "                                          is_piecewise=False,  # 是否为分段型\n",
    "                                          range_text=[\"High\", \"Low\"],\n",
    "                                          border_color=\"#000\"),  # 两端文本\n",
    "\n",
    "        tooltip_opts=opts.TooltipOpts(trigger=\"item\",  # 触发类型\n",
    "                                      trigger_on=\"mousemove|click\",  # 提示框的触发条件\n",
    "                                      formatter=\"{b}:{c} (权重)\")  # 标签内容格式，这里采用的字符串模板\n",
    "    )\n",
    "        .set_series_opts(\n",
    "        label_opts=opts.LabelOpts(is_show=True)\n",
    "    )\n",
    "        .render('html/provience_高校.html')\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
